<?php
// +----------------------------------------------------------------------
// | Tplay [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://tplay.pengyichen.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 听雨 < 389625819@qq.com >
// +----------------------------------------------------------------------
namespace app\wap\model;

use \think\Model;
class City extends Model
{

    public function index($member_pcode='',$partner_id)
    {
        $shu=[];
        $city=[];

        //暂时写死9个城市  西雅图  洛杉矶 旧金山  拉斯维加斯   纽约  华盛顿   奥兰多  温哥华  多伦多
        $cityArr = array(52,56,55,59,57,54,61,77,84);
        foreach ($cityArr as $v){
            $child = $this->where('id',$v)->field('name,thumb as img,eng_name,id as city_id')->find();
            $img = !empty($child['img']) ? explode(',', $child['img']) : '';
            if($img!==''){
                $child['img'] = $img[1];
            }
            $city[]=
                [
                    'name'=> $child['name'],
                    'id'=>$v,
                    'data'=>$child
                ];
        }

        $img=[];
        $d=[];
        $d['show_hidden']=1;
        $d['terminal']=1;


        $d['partner_id'] = 0;//默认系统内
        if(!empty($partner_id)){
            $partner = db("partner")->where("code",$partner_id)->find();
            if(!empty($partner)){
                $partner_id_str = "0,".$partner['id'];
                $d['partner_id'] = ["in",$partner_id_str];
            }
        }

        $img1=db('carousel')
            ->where($d)
            ->order('partner_id desc,img_sort asc')
            ->field('id,img_name,img_src,img_sort,img_url')
            ->select();
        if (!empty($img1)){
            foreach ($img1 as $k=>$v){
                $v['img_url']= json_decode($v['img_url']);
                $img[]=$v;
            }
        }else{
            $img='';
        }

        //积分配置
        $Integral= db('integral')->select();
        $shu=[
            'code'=>0,
            'msg'=>'请求成功',
            'data'=>[
                'image'=>$img,
                'city'=>$city,
                'Integral'=>$Integral,
                'member_pcode'=>$member_pcode,
                'partner_id'=>$partner_id
            ]
        ];

        return $shu;
    }


    public function city(){
        $city=[];
        $fu= $this->where('groupid','0')->where('deleted',0)->select();
        foreach ($fu as $v){
            $child=  $this->where('groupid',$v['id'])->where('deleted',0)->field('name,thumb as img,eng_name,id as city_id')->select();
            $city[]=
                [
                    'name'=> $v['name'],
                    'id'=>$v['id'],
                    'data'=>$child
                ];


        }



        return $city;

    }



}
